//
//  ViewController.swift
//  YJLabelDemo
//
//  Created by 杨永杰 on 2019/8/20.
//  Copyright © 2019年 YYongJie. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var label: YJLabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        label.delegate = self
        label.text = " 跳转到：https://www.baidu.com \n\n 弹出：#星座现场# \n\n 弹出：@张三"        
    }
}


// MARK: - YJLabelDelegate
extension ViewController: YJLabelDelegate {
    
    func yjLabelDidSelectedLinkText(label: YJLabel, text: String) {

        if text.hasPrefix("http") {
            let vc = WebViewController()
            vc.urlString = text
            navigationController?.pushViewController(vc, animated: true)
        } else {
            
            let alert = UIAlertController(title: "您点击了：", message: text, preferredStyle: .alert)
            
            let action = UIAlertAction(title: "知道了", style: .cancel, handler: nil)
            alert.addAction(action)
            present(alert, animated: true, completion: nil)
        }
    }
}
